import { Component } from 'react'
import './index.css'

export default class Footer extends Component {

  handleCheckAll = (event) => {
    const { checkAll } = this.props
    checkAll(event.target.checked)
  }

  handleClearDone = () => {
    const { clearDone } = this.props
    clearDone()
  }

  render() {
    const { todos } = this.props

    const doneCount = todos.reduce((total, todo) => total + (todo.done ? 1 : 0), 0)
    const total = todos.length
    return (
      <div className="todo-footer">
        <label>
          <input type="checkbox" checked={doneCount===total && total!=0} onChange={this.handleCheckAll} />
        </label>
        <span>
          <span>已完成 { doneCount }</span> / 全部 { todos.length }
        </span>
        <button className="btn btn-danger" onClick={this.handleClearDone}>清除已完成任务</button>
      </div>
    )
  }
}
